<template>
    <div>
        <el-card class="card" style="min-width: 1200px">
            <div class="title">
                <h2 style="text-align: center">目标任务录入</h2>
            </div>
        </el-card>
        <br />
        <el-container>
            <el-aside width="350px" style="height: 100vh">
                <el-card>
                    <!--年度查询-->
                    <el-select v-model="value" filterable @change="searchWorkOfTargetYear('A')">
                        <el-option
                            v-for="yearTargetOption in yearTargetOptions"
                            :key="yearTargetOption.value"
                            :label="yearTargetOption.label"
                            :value="yearTargetOption.value"
                        >
                        </el-option>
                    </el-select>
                    <!-- <el-button type="primary" style="margin-left: 5px" @click="searchWorkOfTargetYear">查询</el-button> -->
                </el-card>
                <el-menu>
                    <el-menu-item index="1" @click="clickA">
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ label }} A类</span>
                    </el-menu-item>
                    <div class="menu-buttom" v-show="sideA">
                        <!-- <el-tree :data="taskData" :props="{ label: 'acceptDeptId' }" node-key="id" default-expand-all :expand-on-click-node="false">
                            <span class="custom-tree-node" slot-scope="{ node, data }">
                                <div v-if="node.level == 1">{{data.name}}</div>

                                <span @click="clickNode(node)" v-if="node.level == 1">【{{ node.label }}】{{data.name}}</span>
                                <span @click="clickNode(node)" v-else>{{ node.label }}</span>
                                <span style="position: absolute; right: 5px">
                                    <el-tag type="primary" v-if="node.level == 1">一级</el-tag>
                                    <el-tag type="success" v-if="node.level == 2">二级</el-tag>
                                    <el-tag type="warning" v-if="node.level == 3">三级</el-tag>
                                </span>
                            </span>
                        </el-tree>
                        <hr/> -->
                        <div v-for="(content, i) in taskData" :key="i" class="el-tree-style">
                            <div>
                                <!--任务名称-->
                                <span class="el-tree-node__label menu-click" >{{ content.name }}</span>
                                <div>
                                    <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                    <!--任务接受部门-->
                                    <div style="margin-bottom: 10px; margin-top: -15px">
                                        &ensp;&ensp;<span class="el-tree-node__label menu-click" @click="TaskInfoShow(i)">{{
                                            content.acceptDeptId
                                        }}</span>
                                        <el-tag v-if="content.level == 0">一级</el-tag>
                                        <el-tag type="success" v-if="content.level == 1">二级</el-tag>
                                        <el-tag type="warning" v-if="content.level == 2">三级</el-tag>
                                    </div>

                                    <div style="margin-top: 5px" v-for="(content2, j) in content.children" :key="j">
                                        <!--二级部门-->
                                        <div style="margin-bottom: 10px">
                                            <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                            &ensp;&ensp;<span class="el-tree-node__label menu-click" @click="TaskInfoShowA2(i, j)">{{
                                                content2.acceptDeptId
                                            }}</span>
                                            <el-tag v-if="content2.level == 0">一级</el-tag>
                                            <el-tag type="success" v-if="content2.level == 1">二级</el-tag>
                                            <el-tag type="warning" v-if="content2.level == 2">三级</el-tag>
                                        </div>
                                        <div style="margin-top: 5px" v-for="(content3, n) in content2.children" :key="n">
                                            <!--二级部门-->
                                            <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                            &ensp;&ensp;&ensp;&ensp;<span
                                                class="el-tree-node__label menu-click"
                                                @click="TaskInfoShowA3(i, j, n)"
                                                >{{ content3.acceptDeptId }}</span
                                            >
                                            <el-tag v-if="content3.level == 0">一级</el-tag>
                                            <el-tag type="success" v-if="content3.level == 1">二级</el-tag>
                                            <el-tag type="warning" v-if="content3.level == 2">三级</el-tag>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <br />
                        </div>
                    </div>
                    <el-menu-item index="2" @click="clickB">
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ label }} B类</span>
                    </el-menu-item>
                    <div class="menu-buttom" v-show="sideB">
                        <div v-for="(content, i) in taskBData" :key="i" class="el-tree-style">
                            <div>
                                <span class="el-tree-node__label">【{{ content.allocDeptId }}】{{ content.name }}</span>
                                <div>
                                    <div style="margin-bottom: 10px">
                                        <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                        <span class="el-tree-node__label menu-click" @click="TaskInfoShowB(i)">{{
                                            content.acceptDeptId
                                        }}</span>
                                        <el-tag v-if="content.level == 0">一级</el-tag>
                                        <el-tag type="success" v-if="content.level == 1">二级</el-tag>
                                        <el-tag type="warning" v-if="content.level == 2">三级</el-tag>
                                    </div>
                                    <div style="margin-top: 5px; margin-bottom: 10px" v-for="(content2, j) in content.children" :key="j">
                                        <!--二级部门-->
                                        <span class="is-leaf el-tree-node__expand-icon el-icon-caret-right"></span>
                                        &ensp;&ensp;<span class="el-tree-node__label menu-click" @click="TaskInfoShowB2(i, j)">{{
                                            content2.acceptDeptId
                                        }}</span>
                                        <el-tag v-if="content2.level == 0">一级</el-tag>
                                        <el-tag type="success" v-if="content2.level == 1">二级</el-tag>
                                        <el-tag type="warning" v-if="content2.level == 2">三级</el-tag>
                                    </div>
                                </div>
                            </div>
                            <br />
                        </div>
                    </div>
                    <el-menu-item index="3" @click="clickC">
                        <i class="el-icon-menu"></i>
                        <span slot="title">{{ label }} C类</span>
                    </el-menu-item>
                </el-menu>
            </el-aside>
            <el-main style="padding-top: 0">
                <!--A类3级-->
                <div v-for="(item, index) in taskInfoALast" :key="index" v-show="tabALast" style="margin-bottom: 20px">
                    <span style="font-size: 20px"
                        ><strong>{{ taskHeader }}——{{ taskHeader2 }}——{{ item.name }}</strong></span
                    >
                    <TabATree
                        :taskInfos="item"
                        :targetYear="childYear"
                        :isDept="false"
                        :targetId="childYearId"
                        @refresh="reloadA3"
                        :isPermissionValue="isPermissionValue"
                    ></TabATree>
                </div>
                <!--A类1级-->
                <Tab :taskInfos="taskInfo" :targetYear="childYear" :targetId="childYearId" v-show="tabA" @refresh="reload"></Tab>
                <!--A类2级-->
                <div v-for="(item, index) in taskInfoA3" :key="index" v-show="tabA3" style="margin-bottom: 20px">
                    <span style="font-size: 20px"
                        ><strong>{{ taskHeader }}——{{ item.name }}</strong></span
                    >
                    <TabATree
                        :taskInfos="item"
                        :targetYear="childYear"
                        :isDept="isDept"
                        :targetId="childYearId"
                        :isPermissionValue="isPermissionValue"
                        @refresh="reloadA3"
                    ></TabATree>
                </div>
                <!--B类3级-->
                <div v-for="(item, index) in taskInfoBLast" :key="index" v-show="tabBLast" style="margin-bottom: 20px">
                    <span style="font-size: 20px"
                        ><strong>{{ taskHeader }}——{{ item.name }}</strong></span
                    >
                    <TabATree
                        :taskInfos="item"
                        :targetYear="childYear"
                        :isDept="false"
                        :targetId="childYearId"
                        @refresh="reloadA3"
                        :isPermissionValue="isPermissionValue"
                    ></TabATree>
                </div>
                <TabB :targetYear="childYear" :targetId="childYearId" ref="TabcRef" @func="getTaskBData" v-show="tabB_all"></TabB>
                <TabBView
                    :taskInfos="taskInfo"
                    :targetYear="childYear"
                    :targetId="childYearId"
                    v-show="tabB_view"
                    @refresh="reloadB"
                ></TabBView>
                <TabC :targetYear="childYear" :targetId="childYearId" v-show="tabC"></TabC>
            </el-main>
        </el-container>
    </div>
</template>

<script>
import yearTargetApi from '../../../../api/yearTagetApi';
import departmentApi from '../../../../api/department';
import workOfYearTargetApi from '../../../../api/workOfYearTargetApi';
import Tab from './Tab';
import TabB from './TabBIssue';
import TabBView from './TabB';
import TabC from './TabC.vue';
import TabATree from './TabATree.vue';
export default {
    components: {
        Tab,
        TabB,
        TabC,
        TabBView,
        TabATree
    },
    data() {
        return {
            sideA: false,
            sideB: false,
            sideC: false,
            tabA: false,
            tabB_all: false,
            tabB_view: false,
            tabA3: false,
            yearTargetOptions: [],
            value: '',
            label: '',
            taskData: [],
            // 单个任务的相关信息
            taskInfo: {},
            childYear: '',
            childYearId: '',
            tabC: false,
            taskBData: [],
            taskInfoA3: [],
            taskHeader: '',
            isDept: true,
            tabALast: false,
            taskInfoALast: [],
            taskHeader2: '',
            taskInfoBLast: [],
            tabBLast: false,
            isPermissionValue: true
        };
    },
    methods: {
        clickNode(item){
            console.log(item);
        },
        isPermission(value) {
            let dempartmentLabel = this.$store.state.user.deptId;
            for (let z = 0; z < this.$store.state.department.department.length; ++z) {
                if (this.$store.state.department.department[z].id == dempartmentLabel) {
                    dempartmentLabel = this.$store.state.department.department[z].name;
                    break;
                }
            }
            if (dempartmentLabel == value) {
                this.isPermissionValue = true;
            } else {
                this.isPermissionValue = false;
            }
        },
        async TaskInfoShowB2(i, j) {
            this.taskInfoBLast = [];
            this.tabBLast = true;
            this.tabALast = false;
            this.tabA3 = false;
            this.tabA = false;
            this.tabB_all = false;
            this.tabB_view = false;
            this.tabC = false;
            let departmentId;
            this.taskHeader = this.taskBData[i].name;

            departmentId = this.taskBData[i].acceptDeptId;
            let departmentName = this.taskBData[i].children[j].acceptDeptId;
            this.isPermission(departmentName);
            for (let z = 0; z < this.$store.state.department.department.length; ++z) {
                if (departmentId == this.$store.state.department.department[z].name) {
                    departmentId = this.$store.state.department.department[z].id;
                }
            }
            await workOfYearTargetApi.getTargetTwo(this.taskBData[i].id, 1, departmentId).then((res) => {
                let temp = res.data;
                for (let i = 0; i < temp.length; ++i) {
                    if (temp[i].acceptDeptId == departmentName) {
                        temp[i].isDept = false;
                        this.taskInfoBLast.push(temp[i]);
                    }
                }
            });
        },
        async TaskInfoShowA3(i, j, k) {
            this.taskInfoALast = [];
            this.tabALast = true;
            this.tabBLast = false;
            this.tabA3 = false;
            this.tabA = false;
            this.tabB_all = false;
            this.tabB_view = false;
            this.tabC = false;
            let departmentId;
            this.taskHeader = this.taskData[i].name;
            this.taskHeader2 = this.taskData[i].children[j].name;
            departmentId = this.taskData[i].children[j].acceptDeptId.slice(0, -2);
            let departmentName = this.taskData[i].children[j].children[k].acceptDeptId;
            this.isPermission(departmentName);
            for (let z = 0; z < this.$store.state.department.department.length; ++z) {
                if (departmentId == this.$store.state.department.department[z].name) {
                    departmentId = this.$store.state.department.department[z].id;
                }
            }
            await workOfYearTargetApi.getTargetTwo(this.taskData[i].children[j].id, 1, departmentId).then((res) => {
                let temp = res.data;
                for (let i = 0; i < temp.length; ++i) {
                    if (temp[i].acceptDeptId == departmentName) {
                        temp[i].isDept = false;
                        this.taskInfoALast.push(temp[i]);
                    }
                }
            });
        },
        async TaskInfoShowA2(i, j) {
            this.taskInfoA3 = [];
            this.tabA3 = true;
            this.tabALast = false;
            this.tabA = false;
            this.tabB_all = false;
            this.tabB_view = false;
            this.tabC = false;
            this.tabBLast = false;
            let departmentId;
            let departmentName = this.taskData[i].children[j].acceptDeptId.slice(0, -2);
            this.isPermission(departmentName);
            let isDeptment = true;
            this.taskHeader = this.taskData[i].name;
            for (let x = 0; x < this.$store.state.department.department.length; ++x) {
                if (departmentName == this.$store.state.department.department[x].name) {
                    if (this.$store.state.department.department[x].type == 2) {
                        isDeptment = false;
                        this.isDept = false;
                    } else {
                        isDeptment = true;
                        this.isDept = true;
                    }
                    break;
                }
            }
            for (let j = 0; j < this.$store.state.department.department.length; ++j) {
                if (this.taskData[i].acceptDeptId == this.$store.state.department.department[j].name) {
                    departmentId = this.$store.state.department.department[j].id;
                }
            }

            await workOfYearTargetApi.getTargetTwo(this.taskData[i].id, 0, departmentId).then((res) => {
                let temp = res.data;

                for (let i = 0; i < temp.length; ++i) {
                    if (temp[i].acceptDeptId == departmentName) {
                        temp[i].isDept = this.isDept;
                        this.taskInfoA3.push(temp[i]);
                    }
                }
            });
        },
        reloadA3() {
            // todo
            this.$forceUpdate();
            this.searchWorkOfTargetYear('A');
        },
        reload() {
            this.$forceUpdate();
            this.gettaskData();
        },
        reloadB() {
            this.$forceUpdate();
            this.$refs.TabcRef.searchWorkOfTargetYear();
        },
        // 子传父 B类数据并转树形
        getTaskBData(data) {

            this.taskBData = data;
            this.taskBData = this.toTree2(this.taskBData);
            for (let w = 0; w < this.taskBData.length; ++w) {
                if (this.taskBData[w].children) {
                    this.taskBData[w].children = this.taskBData[w].children.map((item, index) => {
                        return Object.assign({}, { acceptDeptId: item.acceptDeptId, level: item.level });
                    });
                    this.taskBData[w].children = this.unique(this.taskBData[w].children, 'acceptDeptId');
                }
            }

            let tempDataB = this.taskBData;
            this.taskBData = [];
            let dempartmentLabel = this.$store.state.user.deptId;
            for (let z = 0; z < this.$store.state.department.department.length; ++z) {
                if (this.$store.state.department.department[z].id == dempartmentLabel) {
                    dempartmentLabel = this.$store.state.department.department[z].name;
                    break;
                }
            }
            for (let i = 0; i < tempDataB.length; ++i) {
                if (dempartmentLabel == tempDataB[i].acceptDeptId || dempartmentLabel == tempDataB[i].allocDeptId) {
                    this.taskBData.push(tempDataB[i]);
                    continue;
                }
                if (tempDataB[i].children) {
                    for (let j = 0; j < tempDataB[i].children.length; ++j) {
                        if (dempartmentLabel == tempDataB[i].children[j].acceptDeptId) {
                            this.taskBData.push(tempDataB[i]);
                        }
                    }
                }
            }
        },
        // 数组转树
        toTree2(param) {
            //没有父节点的数据
            let parents = param.filter((value) => value.level == 1);

            //有父节点的数据
            let children = param.filter((value) => value.parentId !== 'undefined' && value.parentId != null && value.level == 2);
            //定义转换方法的具体实现
            let translator = (parents, children) => {
                //遍历父节点数据
                parents.forEach((parent) => {
                    //遍历子节点数据
                    children.forEach((current, index) => {
                        //此时找到父节点对应的一个子节点
                        if (current.parentId === parent.id) {
                            //对子节点数据进行深复制，这里只支持部分类型的数据深复制，对深复制不了解的童靴可以先去了解下深复制
                            let temp = JSON.parse(JSON.stringify(children));
                            //让当前子节点从temp中移除，temp作为新的子节点数据，这里是为了让递归时，子节点的遍历次数更少，如果父子关系的层级越多，越有利
                            temp.splice(index, 1);
                            //让当前子节点作为唯一的父节点，去递归查找其对应的子节点
                            translator([current], temp);
                            //把找到子节点放入父节点的children属性中
                            typeof parent.children !== 'undefined' ? parent.children.push(current) : (parent.children = [current]);
                        }
                    });
                });
            };
            //调用转换方法
            translator(parents, children);
            //返回最终的结果
            return parents;
        },
        // 点击A类
        clickA() {
            this.sideA = !this.sideA;
            this.sideB = false;
            this.sideC = false;
            this.tabA = false;
            this.tabB_all = false;
            this.tabB_view = false;
            this.tabC = false;
            this.tabA3 = false;
            this.tabALast = false;
            this.tabBLast = false;
            this.searchWorkOfTargetYear('A');
        },
        clickB() {
            this.$refs.TabcRef.searchWorkOfTargetYear();
            this.sideA = false;
            this.sideB = !this.sideB;
            this.sideC = false;
            this.tabA = false;
            this.tabB_all = true;
            for (let i = 0; i < this.$store.state.department.department.length; ++i) {
                if (this.$store.state.user.deptId == this.$store.state.department.department[i].id) {
                    if (this.$store.state.department.department[i].type == 2) {
                        this.tabB_all = false;
                    }
                }
            }
            this.tabB_view = false;
            this.tabC = false;
            this.tabA3 = false;
            this.tabALast = false;
            this.tabBLast = false;
            // this.searchWorkOfTargetYear('B');
        },
        //——————————————————————————————————————————————————————————————————————————
        // 显示C
        clickC() {
            this.sideA = false;
            this.sideB = false;
            this.sideC = !this.sideC;
            this.tabA = false;
            this.tabB_all = false;
            this.tabB_view = false;
            this.tabC = true;
            this.tabA3 = false;
            this.tabALast = false;
            this.tabBLast = false;
            this.searchWorkOfTargetYear('C');
        },
        // B下发的任务显示任务信息
        TaskInfoShowB(id) {
            this.tabA = false;
            this.tabB_all = false;
            this.tabB_view = true;
            this.tabC = false;
            this.tabA3 = false;
            this.tabALast = false;
            this.tabBLast = false;
            this.childYear = this.label;
            this.taskInfo = this.taskBData[id];
        },
        async getTargetYear() {
            await yearTargetApi.findAll().then((res) => {
                for (let i = 0; i < res.data.length; ++i) {
                    this.yearTargetOptions[i] = {
                        value: res.data[i].id,
                        label: res.data[i].name
                    };
                }
                this.value = this.yearTargetOptions[0].value;
                this.label = this.yearTargetOptions[0].label;
                this.childYear = this.label;
                this.childYearId = this.value;

                // 强制刷新 解决有数据不渲染的问题
                this.$forceUpdate();
            });
        },
        async gettaskData() {
            this.getLabel();
            await workOfYearTargetApi.getWorkOfYearTarget2(this.value, 0).then((res) => {
                this.taskData = res.data;
                this.taskData = this.toTree(this.taskData);
                let tempDataAA = this.taskData;
                this.taskData = [];
                for (let i = 0; i < tempDataAA.length; ++i) {
                    if (this.$store.state.user.deptId == tempDataAA[i].acceptDeptId) {
                        this.taskData.push(tempDataAA[i]);
                        continue;
                    }
                    if (tempDataAA[i].children) {
                        for (let j = 0; j < tempDataAA[i].children.length; ++j) {
                            if (this.$store.state.user.deptId == tempDataAA[i].children[j].acceptDeptId) {
                                this.taskData.push(tempDataAA[i]);
                                break;
                            }

                            if (tempDataAA[i].children[j].children) {
                                for (let k = 0; k < tempDataAA[i].children[j].children.length; ++k) {
                                    if (this.$store.state.user.deptId == tempDataAA[i].children[j].children[k].acceptDeptId) {
                                        this.taskData.push(tempDataAA[i]);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                // departmentid转name
                for (let i = 0; i < this.taskData.length; ++i) {
                    if (this.taskData[i].children) {
                        for (let j = 0; j < this.taskData[i].children.length; ++j) {
                            if (this.taskData[i].children[j].children) {
                                for (let m = 0; m < this.taskData[i].children[j].children.length; ++m) {
                                    for (let n = 0; n < this.$store.state.department.department.length; ++n) {
                                        if (
                                            this.taskData[i].children[j].children[m].acceptDeptId ==
                                            this.$store.state.department.department[n].id
                                        ) {
                                            this.taskData[i].children[j].children[m].acceptDeptId = this.$store.state.department.department[
                                                n
                                            ].name;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                this.formateDeptIdToName();
                this.$forceUpdate();
            });

            this.childYear = this.label;
            this.childYearId = this.value;
        },
        async searchWorkOfTargetYear(item) {
            this.getLabel();
            await workOfYearTargetApi.getWorkOfYearTarget2(this.value, 0).then((res) => {
                let tempTaskData = res.data;
                // this.taskData = res.data;
                // this.taskData = this.toTree(this.taskData);
                tempTaskData = this.toTree(tempTaskData);
                if (item == 'A') {
                    let tempDataAA = tempTaskData;
                    this.taskData = [];
                    for (let i = 0; i < tempDataAA.length; ++i) {
                        if (this.$store.state.user.deptId == tempDataAA[i].acceptDeptId) {
                            this.taskData.push(tempDataAA[i]);
                            continue;
                        }
                        if (tempDataAA[i].children) {
                            for (let j = 0; j < tempDataAA[i].children.length; ++j) {
                                if (this.$store.state.user.deptId == tempDataAA[i].children[j].acceptDeptId) {
                                    this.taskData.push(tempDataAA[i]);
                                    break;
                                }

                                if (tempDataAA[i].children[j].children) {
                                    for (let k = 0; k < tempDataAA[i].children[j].children.length; ++k) {
                                        if (this.$store.state.user.deptId == tempDataAA[i].children[j].children[k].acceptDeptId) {
                                            this.taskData.push(tempDataAA[i]);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (item == 'B') {
                    this.taskData = tempTaskData;
                }
                if (item == 'C') {
                    this.taskData = tempTaskData;
                }
                // departmentid转name
                for (let i = 0; i < this.taskData.length; ++i) {
                    if (this.taskData[i].children) {
                        for (let j = 0; j < this.taskData[i].children.length; ++j) {
                            if (this.taskData[i].children[j].children) {
                                for (let m = 0; m < this.taskData[i].children[j].children.length; ++m) {
                                    for (let n = 0; n < this.$store.state.department.department.length; ++n) {
                                        if (
                                            this.taskData[i].children[j].children[m].acceptDeptId ==
                                            this.$store.state.department.department[n].id
                                        ) {
                                            this.taskData[i].children[j].children[m].acceptDeptId = this.$store.state.department.department[
                                                n
                                            ].name;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                this.formateDeptIdToName();
                this.$forceUpdate();
            });
            //
            this.taskInfo = {};
            this.childYear = this.label;
            this.childYearId = this.value;
        },
        TaskInfoShow(id) {
            this.tabA = true;
            this.tabA3 = false;
            this.tabALast = false;
            this.tabBLast = false;
            this.taskInfo = this.taskData[id];
        },

        async getAllYearTargetWork() {
            await workOfYearTargetApi.getAllWorkOfYearTarget().then((res) => {});
        },
        //————————————————————————————————————————————————————————————————————————————————————————————————
        // 根据value 获取当前的label的值
        getLabel() {
            let obj = {};
            obj = this.yearTargetOptions.find((item) => {
                return item.value == this.value;
            });
            this.label = obj.label;
        },
        // 数组转树
        toTree(param) {
            //没有父节点的数据
            let parents = param.filter((value) => value.level == 0);

            //有父节点的数据
            let children = param.filter(
                (value) => value.parentId !== 'undefined' && value.parentId != null && (value.level == 1 || value.level == 2)
            );
            //定义转换方法的具体实现
            let translator = (parents, children) => {
                //遍历父节点数据
                parents.forEach((parent) => {
                    //遍历子节点数据
                    children.forEach((current, index) => {
                        //此时找到父节点对应的一个子节点
                        if (current.parentId === parent.id) {
                            //对子节点数据进行深复制，这里只支持部分类型的数据深复制，对深复制不了解的童靴可以先去了解下深复制
                            let temp = JSON.parse(JSON.stringify(children));
                            //让当前子节点从temp中移除，temp作为新的子节点数据，这里是为了让递归时，子节点的遍历次数更少，如果父子关系的层级越多，越有利
                            temp.splice(index, 1);
                            //让当前子节点作为唯一的父节点，去递归查找其对应的子节点
                            translator([current], temp);
                            //把找到子节点放入父节点的children属性中
                            typeof parent.children !== 'undefined' ? parent.children.push(current) : (parent.children = [current]);
                        }
                    });
                });
            };
            //调用转换方法
            translator(parents, children);
            //返回最终的结果
            return parents;
        },
        async getDepartmentName(id) {
            await departmentApi.getDepartmentById(id).then((res) => {
                let result = res.data.name;
                return result;
            });
        },
        formateDeptIdToName() {
            for (let i = 0; i < this.taskData.length; ++i) {
                for (let j = 0; j < this.$store.state.department.department.length; ++j) {
                    if (this.taskData[i].acceptDeptId == this.$store.state.department.department[j].id) {
                        this.taskData[i].acceptDeptId = this.$store.state.department.department[j].name;
                    }
                    if (this.taskData[i].allocDeptId == this.$store.state.department.department[j].id) {
                        this.taskData[i].allocDeptId = this.$store.state.department.department[j].name;
                    }
                }
                if (this.taskData[i].children) {
                    for (let n = 0; n < this.taskData[i].children.length; ++n) {
                        for (let x = 0; x < this.$store.state.department.department.length; ++x) {
                            if (this.taskData[i].children[n].acceptDeptId == this.$store.state.department.department[x].id) {
                                this.taskData[i].children[n].acceptDeptId = this.$store.state.department.department[x].name;
                            }
                        }
                    }
                    // this.taskData[i].children = this.taskData[i].children.map((item, index) => {
                    //     return Object.assign({}, { acceptDeptId: item.acceptDeptId, level: item.level });
                    // });
                }
            }
            for (let i = 0; i < this.taskData.length; ++i) {
                let obj = {};
                if (this.taskData[i].children) {
                    for (let j = 0; j < this.taskData[i].children.length; ++j) {
                        let item = this.taskData[i].children[j].acceptDeptId;
                        obj[item] = obj[item] + 1 || 1;
                        let temp = obj[item] >= 10 ? obj[item] : '0' + obj[item];
                        this.taskData[i].children[j].acceptDeptId = this.taskData[i].children[j].acceptDeptId + temp;
                    }
                }
            }
            for (let z = 0; z < this.taskData.length; ++z) {
                if (this.taskData[z].children) {
                    for (let p = 0; p < this.taskData[z].children.length; ++p) {
                        if (this.taskData[z].children[p].children) {
                            this.taskData[z].children[p].children = this.unique(this.taskData[z].children[p].children, 'acceptDeptId');
                        }
                    }
                    // this.taskData[z].children = this.unique(this.taskData[z].children, 'acceptDeptId');
                }
            }
        },

        unique(arr, attrName) {
            const res = new Map();
            return arr.filter((a) => !res.has(a[attrName]) && res.set(a[attrName], 1));
        }
    },
    created() {
        this.searchWorkOfTargetYear();
        this.getTargetYear();
        this.getAllYearTargetWork();
        this.$store.dispatch('getDepartment');
        this.$store.dispatch('getTeachers');
    },
    watch:{
        taskData(){
            console.log(this.taskData);
        }
    }
};
</script>

<style scoped>
.el-tree-style {
    padding: 0px 40px;
}
.el-tree-node__label {
    color: #606266;
}
.el-tag {
    float: right;
}
.title {
    border: 1px #bcbcbc;
    width: 50%;
    margin: 0 auto;
}
.card {
    border-radius: 15px;
    width: 50%;
    margin: 0 auto;
}
.el-menu-item.is-active {
    color: #409eff;
}
.menu-buttom {
    padding-bottom: 20px;
}
.menu-click {
    cursor: pointer;
}
</style>
<style >
div /deep/ .el-table thead {
    color: #000;
}
</style>